import 'package:get/get.dart';
import 'package:word_app/app/modules/model/app_https_client.dart';
import 'package:word_app/app/modules/model/user_model.dart';

class MineController extends GetxController {
  List dataSoure = [
    {"img": "Feedback.png", "title": "意见反馈", "bz": ""},
    {"img": "versionNumber.png", "title": "版本号", "bz": "v1.0.0"},
    {"img": "loginout.png", "title": "退出登录", "bz": ""},
    {"img": "cancelAccount.png", "title": "注销", "bz": ""}
  ];
  RxString phoneStr = "".obs;
  AppHttpsClient httpsclient = AppHttpsClient();
  RxString photoStr = "".obs;
  @override
  void onInit() {
    super.onInit();
    try {
      UserModel? usermodel = MyUserData.userModel;
      if (usermodel != null) {
        phoneStr.value = usermodel.data!.user!.phone!;
        photoStr.value = usermodel.data!.user!.headerImg!;
        update();
      }
    } catch (e) {
      print(e);
    }
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  String maskPhoneNumber(String phoneNumber) {
    if (phoneNumber.length < 11) {
      return phoneNumber;
    }
    return "${phoneNumber.substring(0, 3)}****${phoneNumber.substring(phoneNumber.length - 4)}";
  }

//退出登录
  Future<bool> loginOut() async {
    var response = await httpsclient.post("jwt/jsonInBlacklist", null);
    try {
      if (response.data["code"] == 200) {
        return true;
      } else {
        return false;
      }
    } catch (e) {
      return false;
    }
  }

//注销账号
  Future<bool> deleteAccount() async {
    var response = await httpsclient.post("user/deleteAccount", null);
    try {
      if (response.data["code"] == 200) {
        return true;
      } else {
        return false;
      }
    } catch (e) {
      return false;
    }
  }
}
